package com.xjtu.platform.admin.user;

import com.xjtu.platform.common.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/admin/user")
public class UserAPI {

    @Resource
    private UserService userService;

    @GetMapping("/getUserInfo")
    public Result getUserInfo(UserDto userDto){

        Map<String,Object> page = userService.getUserList(userDto);

        return Result.success(page);
    }

    @PostMapping("/userAdd")
    public Result userAdd(@RequestBody NewUserDto newUserDto){
        boolean ok = userService.addUser(newUserDto);
        if(ok){
            return Result.success("新增成功！！！");
        }else {
            return Result.fail(Result.ERR_CODE_SYS,"系统维护中......");
        }
    }

    @PostMapping("/deleteUser")
    public Result userDelete(@RequestBody DeletedUserDto deletedUserDto){
        boolean ok = userService.deleteUser(deletedUserDto);
        if(ok){
            return Result.success("删除成功！！！");
        }else {
            return Result.fail(Result.ERR_CODE_SYS,"系统维护中......");
        }
    }

    @PostMapping("/changeUser")
    public Result changeUserRole(@RequestBody ChangeRoleDto changeRoleDto){
        boolean ok = userService.changeRole(changeRoleDto);
        if(ok){
            return Result.success("修改成功！！！");
        }else {
            return Result.fail(Result.ERR_CODE_SYS,"系统维护中......");
        }
    }


}
